{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 2,
   "id": "initial_id",
   "metadata": {
    "collapsed": true,
    "ExecuteTime": {
     "end_time": "2024-10-23T07:06:17.743700Z",
     "start_time": "2024-10-23T07:06:17.729747Z"
    }
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "你是一个业务咨询顾问。\n",
      "你给销售鲜花的电商公司，起一个好的名字？\n",
      "\n",
      "input_variables=['product'] input_types={} partial_variables={} template='你是一个业务咨询顾问。\\n你给销售{product}的电商公司，起一个好的名字？\\n'\n"
     ]
    }
   ],
   "source": [
    "from langchain import PromptTemplate\n",
    "template = \"\"\"\\\n",
    "你是一个业务咨询顾问。\n",
    "你给销售{product}的电商公司，起一个好的名字？\n",
    "\"\"\"\n",
    "prompt = PromptTemplate.from_template(template)\n",
    "print(prompt.format(product=\"鲜花\"))\n",
    "print(prompt)"
   ]
  },
  {
   "cell_type": "code",
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "你是业务咨询顾问，对于一个面向高端市场的，专注于销售鲜花的公司，你会推荐哪个名字？\n"
     ]
    }
   ],
   "source": [
    "prompt = PromptTemplate(\n",
    "    input_variables = [\"product\", \"market\"],\n",
    "    template=\"你是业务咨询顾问，对于一个面向{market}市场的，专注于销售{product}的公司，你会推荐哪个名字？\"\n",
    ")\n",
    "print(prompt.format(product=\"鲜花\", market=\"高端\"))"
   ],
   "metadata": {
    "collapsed": false,
    "ExecuteTime": {
     "end_time": "2024-10-23T07:16:52.391286Z",
     "start_time": "2024-10-23T07:16:52.379326Z"
    }
   },
   "id": "d39542f0f95c3bf4",
   "execution_count": 3
  },
  {
   "cell_type": "code",
   "outputs": [],
   "source": [
    "from langchain.prompts import (\n",
    "    ChatPromptTemplate,\n",
    "    SystemMessagePromptTemplate,\n",
    "    HumanMessagePromptTemplate,\n",
    ")"
   ],
   "metadata": {
    "collapsed": false,
    "ExecuteTime": {
     "end_time": "2024-10-24T00:30:33.775222Z",
     "start_time": "2024-10-24T00:30:33.766253Z"
    }
   },
   "id": "f6d1a3be74f4a669",
   "execution_count": 2
  },
  {
   "cell_type": "code",
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "prompt=PromptTemplate(input_variables=['product'], input_types={}, partial_variables={}, template='你是一位专业顾问，负责为专注于{product}的公司起名。') additional_kwargs={} \n",
      "\n",
      "prompt=PromptTemplate(input_variables=['product_detail'], input_types={}, partial_variables={}, template='公司主打产品是{product_detail}。') additional_kwargs={} \n"
     ]
    }
   ],
   "source": [
    "template=\"你是一位专业顾问，负责为专注于{product}的公司起名。\"\n",
    "system_message_prompt=SystemMessagePromptTemplate.from_template(template)\n",
    "print(system_message_prompt,\"\\n\")\n",
    "\n",
    "human_template=\"公司主打产品是{product_detail}。\"\n",
    "human_message_prompt=HumanMessagePromptTemplate.from_template(human_template)\n",
    "print(human_message_prompt,\"\\n\")"
   ],
   "metadata": {
    "collapsed": false,
    "ExecuteTime": {
     "end_time": "2024-10-24T00:30:35.441932Z",
     "start_time": "2024-10-24T00:30:35.432962Z"
    }
   },
   "id": "75f1e9447c5345a",
   "execution_count": 3
  },
  {
   "cell_type": "code",
   "outputs": [
    {
     "ename": "NameError",
     "evalue": "name 'prompt' is not defined",
     "output_type": "error",
     "traceback": [
      "\u001B[1;31m---------------------------------------------------------------------------\u001B[0m",
      "\u001B[1;31mNameError\u001B[0m                                 Traceback (most recent call last)",
      "Cell \u001B[1;32mIn[4], line 2\u001B[0m\n\u001B[0;32m      1\u001B[0m prompt_template\u001B[38;5;241m=\u001B[39mChatPromptTemplate\u001B[38;5;241m.\u001B[39mfrom_messages([system_message_prompt, human_message_prompt])\n\u001B[1;32m----> 2\u001B[0m \u001B[38;5;28mprint\u001B[39m(\u001B[43mprompt\u001B[49m)\n",
      "\u001B[1;31mNameError\u001B[0m: name 'prompt' is not defined"
     ]
    }
   ],
   "source": [
    "prompt_template=ChatPromptTemplate.from_messages([system_message_prompt, human_message_prompt])\n",
    "print(prompt)"
   ],
   "metadata": {
    "collapsed": false,
    "ExecuteTime": {
     "end_time": "2024-10-24T00:30:36.672099Z",
     "start_time": "2024-10-24T00:30:36.634227Z"
    }
   },
   "id": "e6efde39f9d9711b",
   "execution_count": 4
  },
  {
   "cell_type": "code",
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "[SystemMessage(content='你是一位专业顾问，负责为专注于鲜花装饰的公司起名。', additional_kwargs={}, response_metadata={}), HumanMessage(content='公司主打产品是创新的鲜花设计。', additional_kwargs={}, response_metadata={})]\n"
     ]
    }
   ],
   "source": [
    "prompt = prompt_template.format_prompt(product=\"鲜花装饰\", product_detail=\"创新的鲜花设计\").to_messages()\n",
    "print(prompt)"
   ],
   "metadata": {
    "collapsed": false,
    "ExecuteTime": {
     "end_time": "2024-10-24T00:30:38.027639Z",
     "start_time": "2024-10-24T00:30:38.017673Z"
    }
   },
   "id": "dcd2b313c2b35c03",
   "execution_count": 5
  },
  {
   "cell_type": "code",
   "outputs": [
    {
     "data": {
      "text/plain": "'为您公司的命名建议如下：\\n\\n1. \"花艺创想\": 这个名字直接表明了您公司在花卉创意方面的专注和独特性。\\n\\n2. \"花瓣设计师\": 此名称突出了您的公司将致力于把每一片花瓣都视为艺术作品，注重每一个细节的设计。\\n\\n3. \"花境无限\": 代表公司拥有无尽的创新力和想象力,能够创造出各种独特的鲜花装饰设计。\\n\\n4. \"创意花卉\": 简洁明了地传达了您公司的核心理念——将传统花卉与现代设计理念相结合，推出具有独特风格的产品和服务。\\n\\n5. \"花语奇缘\": 此名既富有诗意又充满神秘色彩，暗示着公司能为顾客提供一种不同寻常的体验。同时，“花语”一词也能让人联想到鲜花背后所蕴含的情感和意义。 \\n\\n6. \"梦幻花卉\":\"梦幻\"意指美好、不可思议的事物,此名称可以激发人们对您产品的好奇心和期待感。\\n\\n请根据您的具体需求和偏好选择合适的名字！'"
     },
     "execution_count": 10,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "from get_ollama import GetOllama\n",
    "from langchain_core.output_parsers import StrOutputParser\n",
    "chat=GetOllama(ip=GetOllama.ailab_linux_ip, model_name=\"qwen2.5:14b\", model_type=1)()\n",
    "chat.invoke(prompt).content\n"
   ],
   "metadata": {
    "collapsed": false,
    "ExecuteTime": {
     "end_time": "2024-10-24T00:38:02.384611Z",
     "start_time": "2024-10-24T00:37:56.937357Z"
    }
   },
   "id": "393aae77fab4dfa3",
   "execution_count": 10
  },
  {
   "cell_type": "code",
   "outputs": [],
   "source": [],
   "metadata": {
    "collapsed": false
   },
   "id": "b5518964b5ebb85c"
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 2
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython2",
   "version": "2.7.6"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
